<?php 

//添加用户
	function addUserInfo($userObj) {

//服务器地址，用户名，密码，数据库名
		$mysql = new mysqli(SAE_MYSQL_HOST_M.":".SAE_MYSQL_PORT, SAE_MYSQL_USER, SAE_MYSQL_PASS, SAE_MYSQL_DB);
		$mysql -> query("set names utf8");

		$nickname = $userObj -> nickname;
		$sex = $userObj -> sex;
		$country = $userObj -> country;
		$province = $userobj -> province;
	//城市
		$city = $userObj -> city;
	//头像信息
		$headimgurl = $userObj -> headimgurl;
	//性别
		$sexNumber = $userObj -> sex;
		if($sexNumber == 1) {
			$sex = '男';
		} else if($sexNumber == 2) {
			$sex = '女';
		} else {
			$sex = '未知';
		}

		$sql = "insert into inno(id, openid, nickname, sex, country, province, city, headimgurl, score) values( '{$id}', '{$openid}', '{$nickname}', '{$sex}', '{$country}', '{$province}', '{$city}', '{$headimgurl}', '{$score}')";
		$result = $mysql -> query($sql);
		if($result) {
			return "success";
		} else {
			return "false";
		}
		$mysql -> close();

	}

//更新分数
	function updateScore($userObj, $score) {
		$mysql = new mysqli(SAE_MYSQL_HOST_M.":".SAE_MYSQL_PORT, SAE_MYSQL_USER, SAE_MYSQL_PASS, SAE_MYSQL_DB);
		$mysql -> query("set names utf8");

		$openid = $userObj -> openid;


		$sql = "update inno set score = '$score' where openid = '$openid'";
		$result = $mysql -> query($sql);
		$mysql -> close();



	} 


// 查询所有的分数
	function selectScore() {
		$mysql = new mysqli(SAE_MYSQL_HOST_M.":".SAE_MYSQL_PORT, SAE_MYSQL_USER, SAE_MYSQL_PASS, SAE_MYSQL_DB);
		$mysql -> query("set names utf8");

//通过分数降序排序
		$sql = "select * from inno order by score desc";
		$result = $mysql -> query($sql);
		while($result2 = $result -> fetch_row()) {
			$nickname = $result2["nickname"];
			$score = $result2["score"];
			echo $nickname."   ".$score;
			echo "<br>";
		}
		
	}




 ?>